package rs.daolao.syc.admin.account.dao.persist.repository.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import rs.dalao.syc.common.pojo.vo.PageData;
import rs.dalao.syc.common.util.PageInfoToPageDataConverter;
import rs.daolao.syc.admin.account.dao.persist.mapper.DoctorMapper;
import rs.daolao.syc.admin.account.dao.persist.mapper.UserMapper;
import rs.daolao.syc.admin.account.dao.persist.repository.IUserRepository;
import rs.daolao.syc.admin.account.pojo.entity.Doctor;
import rs.daolao.syc.admin.account.pojo.entity.User;
import rs.daolao.syc.admin.account.pojo.vo.*;

import java.util.List;

/**
 * 处理用户数据的存储库实现类
 *
 * @author java@tedu.cn
 * @version 2.0
 */
@Slf4j
@Repository
public class UserRepositoryImpl implements IUserRepository {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private DoctorMapper doctorMapper;

    public UserRepositoryImpl() {
        log.info("创建存储库对象：UserRepositoryImpl");
    }


    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【根据ID删除用户】的数据访问，参数：{}", id);
        return userMapper.deleteById(id);
    }

    @Override
    public int updateById(User user) {
        log.debug("开始执行【更新用户】的数据访问，参数：{}", user);
        return userMapper.updateById(user);
    }

    @Override
    public int updateByDoctorId(Doctor doctor) {
        log.debug("开始执行【更新医生】的数据访问，参数：{}", doctor);
        return doctorMapper.updateById(doctor);
    }

    @Override
    public DoctorStandardVO getSearchByDoctorId(Long id) {
        log.debug("开始执行【查询医生】的数据访问，：{}",id);
        return doctorMapper.getDocStandardSearch(id);
    }

    @Override
    public UserStandardVO getStandardById(Long id) {
        log.debug("开始执行【根据ID查询用户详情】的数据访问，参数：{}", id);
        return userMapper.getStandardById(id);
    }

    @Override
    public PageData<UserListItemVO> UserList(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询用户列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<UserListItemVO> list = userMapper.userList();
        PageInfo<UserListItemVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }
    @Override
    public PageData<DoctorListVO> doctorList(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询用户列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<DoctorListVO> list = userMapper.doctorList();
        PageInfo<DoctorListVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

    @Override
    public PageData<UsersSearchVO> userSearch(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询用户列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<UsersSearchVO> list = userMapper.listSearch();
        PageInfo<UsersSearchVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }


}
